package com.ssis.core;

import java.util.EnumMap;

import com.ssis.core.Cell.CellType;

public class Crew {
	private CrewStat[] stats;
	public static enum CellLocation {
		SLEEP,
		WORK,
		COMBAT,
		EAT,
		ACTIVEREC,
		PASSIVEREC,
		REFRESHER,
		MEDIC
	}
	
	private EnumMap<CellLocation, Cell> locationTypes;
	private String name;
//	private int title;
//	private int salary;
//	private boolean isInjured;
//	private Cell SleepCell;
//	private Cell WorkCell;
//	private Cell CombatCell;
//	private Cell MessCell;
//	private Cell ActiveRecCell;
//	private Cell PassiveRecCell;
//	private Cell RefresherCell;
//	private Weapon weapon;
//	private Armor armor;
	
	public Crew() {
		stats = new CrewStat[9];
		stats[0] = new CrewStat("Engineer");
		stats[1] = new CrewStat("Research");
		stats[2] = new CrewStat("Business");
		stats[3] = new CrewStat("Cook");
		stats[4] = new CrewStat("Gardener");
		stats[5] = new CrewStat("Medic");
		stats[6] = new CrewStat("Weapons");
		stats[7] = new CrewStat("Helmsman");
		stats[8] = new CrewStat("Soldier");
		name = CrewNameGenerator.randomName();
		locationTypes = new EnumMap<CellLocation, Cell>(CellLocation.class);
	}

	public Cell getLocation(CellLocation location) {
		if(locationTypes.containsKey(location))
			return locationTypes.get(location);
		return null;
	}
	
	/**
	 * Changes the cell this crewmember uses for a particular task
	 * @param type task, such as sleeping quarters
	 * @param location new cell used
	 */
	public void setLocation(CellLocation type, Cell location) {
		if(locationTypes.containsKey(type)) {
			locationTypes.remove(type);
			location.removeCrew(this);
		}
		locationTypes.put(type, location);
	}
	
	public int morale() {
		int morale = 0;
		Cell c = getLocation(CellLocation.SLEEP);
		if (c == null)
			return 0;
		if (c.getType() == CellType.DORM)
			morale += 1;
		if (c.getType() == CellType.QUARTERS)
			morale += 2;
		if (c.crewCapacity() >= c.crewSize()/2)
			morale *= 2;
		c = getLocation(CellLocation.WORK);
		if (c != null)
			morale += 1;
		return morale;
	}
	
	public String name() {
		return name;
	}
}
